//
//  PhoneUtil.m
//  HealthManager_Customer
//
//  Created by lzh on 2017/12/19.
//  Copyright © 2017年 Facebook. All rights reserved.
//

#import "PhoneUtil.h"
#import <AdSupport/ASIdentifierManager.h>

@implementation PhoneUtil

+ (CGSize)screenSize
{
    CGSize screenSize =[UIScreen mainScreen].bounds.size;
    
    return screenSize;
    
}

+ (BOOL) isIPhoneX
{
    CGSize screenSize = [self screenSize];
    
    if (@available(iOS 11.0, *)) {
        /// 利用safeAreaInsets.bottom > 0.0来判断是否是iPhone X。
        UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
        if (mainWindow.safeAreaInsets.bottom > 0.0) {
            return YES;
        }
    }
    return NO;
}


+ (NSInteger) screenWidth
{
    CGSize screenSize = [self screenSize];
    
    return screenSize.width;
}

+ (NSInteger) screenHeight
{
    CGSize screenSize = [self screenSize];
    
    return screenSize.height;
}

+ (CGFloat) statusBarHeight
{
    //    if([self isIPhoneX]){
    //        return 44;
    //    }
    //
    //    return 20;
    
    return [UIApplication sharedApplication].statusBarFrame.size.height;
    
}

+ (CGFloat)tabbarAdjustHeight
{
    if ([self isIPhoneX]) {
        return 32;
    }
    
    return 0.;
}

+ (CGFloat)tabbarHeight
{
    return 49 + [self tabbarAdjustHeight];
}

+ (CGFloat) scale
{
    return [UIScreen mainScreen].scale;
}

+ (CGFloat) line{
    return 1.0 / [self scale];
}

+ (CGFloat)topAdjustHeightWithNavi:(BOOL)hasNavi
{
    CGFloat naviHeight = 0;
    if (hasNavi) {
        naviHeight = 44.f;
    }
    return [self statusBarHeight] + naviHeight;
}

+ (NSString*)uuid {
    NSString *result = [UIDevice currentDevice].identifierForVendor.UUIDString;
    return result.length ? result : @"";
}

+ (NSString *)mobileOsVersion
{
    static NSString *version = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        version = [UIDevice currentDevice].systemVersion;
    });
    
    return version;
}

+ (NSString *)mobileOs
{
    return @"iOS";
}



+ (NSString*)getIDFA{
    
    NSString* idfa = nil;
    
    if ([ASIdentifierManager sharedManager].advertisingTrackingEnabled) {
        idfa = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
    }
    
    if (idfa.length == 0) {
        idfa = @"123";
    }
    
    return idfa;
}

@end
